#include "pch.h"

sf::Music Music0, Music1, MusicMenu;
std::vector<std::pair<sf::SoundBuffer,std::string> > Sounds;
std::vector<sf::Sound> Players;

bool handleMusic()
{	
	Sounds.push_back(std::pair<sf::SoundBuffer,std::string>(sf::SoundBuffer(),"FallEgg_0"));
	if (!Sounds.back().first.LoadFromFile("data/music/FallEgg_0.ogg")) return false;
	Sounds.push_back(std::pair<sf::SoundBuffer,std::string>(sf::SoundBuffer(),"FallEgg_1"));
	if (!Sounds.back().first.LoadFromFile("data/music/FallEgg_1.ogg")) return false;
	Sounds.push_back(std::pair<sf::SoundBuffer,std::string>(sf::SoundBuffer(),"CatchEgg_0"));
	if (!Sounds.back().first.LoadFromFile("data/music/CatchEgg_0.ogg")) return false;
	Sounds.push_back(std::pair<sf::SoundBuffer,std::string>(sf::SoundBuffer(),"CatchEgg_1"));
	if (!Sounds.back().first.LoadFromFile("data/music/CatchEgg_1.ogg")) return false;
	Sounds.push_back(std::pair<sf::SoundBuffer,std::string>(sf::SoundBuffer(),"Fox"));
	if (!Sounds.back().first.LoadFromFile("data/music/fox.ogg")) return false;
	Sounds.push_back(std::pair<sf::SoundBuffer,std::string>(sf::SoundBuffer(),"Door"));
	if (!Sounds.back().first.LoadFromFile("data/music/Door.ogg")) return false;

	Music0.OpenFromFile("data/music/sad.ogg");
	Music1.OpenFromFile("data/music/happy.ogg");
	MusicMenu.OpenFromFile("data/music/menu.ogg");

	Music0.SetLoop(true);
	Music1.SetLoop(true);
	MusicMenu.SetLoop(true);

	Players.resize(Sounds.size());

	return true;
}

void playSound(std::string name)
{
	int i;

	std::vector<std::pair<sf::SoundBuffer,std::string> >::iterator it;
	for (i = 0; i < Sounds.size(); ++i)
		if (Sounds[i].second == name)
			break;

	Players[i].SetBuffer(Sounds[i].first);
	Players[i].Play();
}